// Token存储键名
const TOKEN_KEY = 'cherry_token';
const USER_INFO_KEY = 'cherry_user_info';

// 保存Token到本地
export const saveToken = (token) => {
  if (token) {
    uni.setStorageSync(TOKEN_KEY, token);
  }
};

// 获取Token
export const getToken = () => {
  return uni.getStorageSync(TOKEN_KEY) || '';
};

// 移除Token
export const removeToken = () => {
  uni.removeStorageSync(TOKEN_KEY);
};

// 保存用户信息
export const saveUserInfo = (userInfo) => {
  if (userInfo) {
    uni.setStorageSync(USER_INFO_KEY, JSON.stringify(userInfo));
  }
};

// 获取用户信息
export const getUserInfo = () => {
  const userInfoStr = uni.getStorageSync(USER_INFO_KEY);
  return userInfoStr ? JSON.parse(userInfoStr) : null;
};

// 移除用户信息
export const removeUserInfo = () => {
  uni.removeStorageSync(USER_INFO_KEY);
};

// 检查是否登录
export const isLoggedIn = () => {
  return !!getToken();
};

// 退出登录
export const logout = () => {
  removeToken();
  removeUserInfo();
}; 